{extend name="mainadmin@layouts/base" /}
{block name="main" }

<header class="header  b-b clearfix">
    <form id="forms" class="talbe-search form-inline " method="post" action="{:url('getList')}">
        <div class="page-breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="fa fa-ellipsis-v"></i>
                    <strong>管理权限列表</strong>
                </li>
            </ul>

            <a href="{:url('info')}" data-toggle="ajaxModal" title="添加权限"
               class="btn btn-sm btnbtn-default fr  m-t-md m-r"><i class="fa fa-plus m-r-xs"></i>添加权限</a>
        </div>
    </form>
</header>

<section class="scrollable wrapper w-f ">
    <section class="panel panel-default ">
        <div class="table-responsive " id="list_box">
            {include file="admin_priv/list" /}
        </div>
    </section>
</section>
<script type="text/javascript">
    $(document).on('change', '#group-select', function () {
        $(document).find('#controller option:eq(0)').attr("selected", true);
        $(document).find('#controller option:gt(0)').addClass('hide');
        $(document).find('.option-' + $(this).val()).removeClass('hide');
    })
    $(document).on('change', '#controller', function () {
        jq_ajax('{:url("getClassAction")}', 'controller=' + $(this).val(), function (res) {
            $('#fun_list').find('option:gt(0)').remove();
            $('#fun_list').append(res.data.html);
        })
    })
    function add_right() {
        var a = [];
        $('#rightList .form-control').each(function (i, o) {
            if ($(o).val() != '') {
                a.push($(o).val());
            }
        })
        var ncode = $('#controller').val();
        if (ncode == '') {
            layer.msg('请选择控制器.', {icon: 2, time: 1000});
            return false;
        }

        var temp = ncode + ':' + $('#fun_list').val();
        if ($.inArray(temp, a) != -1) {
            layer.msg('此权限码已经添加！', {icon: 2, time: 1000});
            return false;
        }
        var strtr = '<tr>';
        if (ncode != '') {
            strtr += '<td><input type="text" name="right[]" value="' + ncode + ':' + $('#fun_list').val() + '" class="form-control" style="width:300px;"></td>';
        } else {
            strtr += '<td><input type="text" name="right[]" value="" class="form-control" style="width:300px;"></td>';
        }
        strtr += '<td style="text-align: center;"><a href="javascript:;" class="ncap-btn" onclick="$(this).parent().parent().remove();">删除</a></td>';
        $('#rightList').append(strtr);
    }
</script>
{/block}
